<template>
	<view class="container">

		<view>
			<u--form labelPosition="left" :model="form" :rules="rules" ref="form" labelWidth='100px'
				:labelStyle='labelStyle'>
				
				
				<view class="box">
					<user-pick :label="'检测人'" :multiple="false" :title="'检测人'" :placeholder="'请选择检测人'"
						v-model="form.jcr" :prop="'jcr'"></user-pick>
						
					<u-form-item label="检测日期" prop="jcrq" borderBottom @click="show=true">
						<u--input v-model="form.jcrq" placeholder="请选择检测日期" disabledColor="#ffffff" disabled
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right" ></u-icon>
					</u-form-item>
					
					<u-calendar :show="show" @close='show=false' @confirm="confirm"></u-calendar>
					
					<dept :label="'检测部门'" :title="'检测部门'" :placeholder="'请选择检测部门'" v-model="form.jcrdw" :prop="'jcrdw'"></dept>
					<u-form-item label="" prop="jcnr" >
						<view class="textarea">
							<text class="title">检测内容</text>
							<view class="tarea">
								<textarea
									style="background-color: #F6F6F6;color: #666666;font-size: 28rpx;border-radius: 8rpx; padding: 24rpx 0 24rpx 10rpx;"
									v-model="form.jcnr" placeholder="请输入……" rows="3"></textarea>
							</view>
						</view>
					</u-form-item>
					<u-form-item label="检测状态" prop="jcztName" borderBottom  @click="show2=true">
						<u--input v-model="form.jcztName" placeholder="选择检测状态" disabledColor="#ffffff" disabled border="none"></u--input>
						<u-icon slot="right" name="arrow-right" ></u-icon>
					</u-form-item>
					<u-picker :show="show2" :columns="columns2" keyName="label" @confirm='confirm2'
						@cancel='show2=false'></u-picker>
					<u-form-item label="保养日期" prop="byrq" borderBottom @click="show1=true">
						<u--input v-model="form.byrq" placeholder="请选保养日期" disabledColor="#ffffff" disabled
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right" ></u-icon>
					</u-form-item>
					<u-calendar :show="show1" @close='show1=false' @confirm="confirm1"></u-calendar>
					
				</view>
			</u--form>
			<u-button type="primary" text="确认" @click="submit" class='but'></u-button>
		</view>
	</view>
</template>

<script>
	import {
		jcadd1,
	} from '@/api/equipment'
	import {
		URL
	} from '@/api/request.js'
	import userPick from "@/pages/Components/userPick";
	import dept from "@/pages/Components/department";
	export default {
		components: {
			userPick,
			dept
		},
		data() {
			return {
				show: false,
				show1: false,
				show2: false,
				labelStyle: {
					color: '#666'
				},
				form: {
					scssid:'',
					jcr: '',
					jcrq: '',
					jcrdw: '',
					jcnr: '',
					jcztName: '',
					byrq: '',
				},
				id: '',
				columns2: [
					[{
						label: '正常',
						id: 1
					}, {
						label: '异常',
						id: 2
					}]
				],
				rules: {
					'jcr': {
						type: 'string',
						required: true,
						message: '不能为空',
						trigger: ['blur', 'change']
					},
					'jcrrq': {
						type: 'string',
						required: true,
						message: '不能为空',
						trigger: ['blur', 'change']
					},
					'jcrdw': {
						type: 'string',
						required: true,
						message: '不能为空',
						trigger: ['blur', 'change']
					},
					'jcnr': {
						type: 'string',
						required: true,
						message: '不能为空',
						trigger: ['blur', 'change']
					},
					'jcztName': {
						type: 'string',
						required: true,
						message: '不能为空',
						trigger: ['blur', 'change']
					},
					'byrq': {
						type: 'string',
						required: true,
						message: '不能为空',
						trigger: ['blur', 'change']
					},

				},
			};
		},
		onLoad(option) {
			this.form.scssid = option.scssid
		},
		onShow() {
			
		},
		methods: {

			// 选择日期
			confirm(val) {
				this.form.jcrq = val[0].replace(new RegExp("-", "gm"), "");
				this.show = false
			},
			confirm1(val) {
				this.form.byrq = val[0].replace(new RegExp("-", "gm"), "");
				this.show1 = false
			},
			// 检测状态
			confirm2(val) {
				this.form.jczt = val.value[0].id
				this.form.jcztName = val.value[0].label
				this.show2 = false
			},
			submit() {

				this.$refs.form.validate().then(res => {
					uni.$u.toast('校验通过')
					jcadd1(this.form).then(res => {
						uni.$u.toast('编辑成功')
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)

					})
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})

			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f5f5;
	}

	.container {
		padding: 0 24rpx;
		background-color: #f6f6f6;

		.title {
			font-size: 28rpx;
			font-weight: 500;
			line-height: 44rpx;
			padding: 20rpx 0;
		}

		.box {
			padding: 0rpx 48rpx;
			background-color: #fff;
			border-radius: 20rpx;
		}

		.textarea {
			
			.one {
				font-size: 28rpx;
				color: #999999;
			}

			.tarea {
				margin-top: 16rpx;
			}
		}
	}

	.but {
		margin: 30rpx 0;
	}
</style>
